//
//  B_GZZCSViewController.m
//  Estate
//
//  Created by heyong on 16/6/16.
//  Copyright © 2016年 ttsx. All rights reserved.
//

#import "B_GZZCSViewController.h"
#import "HeadView_1.h"
#import "QianDTableCell.h"
#import "C_wladdCell_1.h"

@interface B_GZZCSViewController ()
{
    NSArray *titleArr;
}

@end

@implementation B_GZZCSViewController
//
//- (void)setSite:(Site_05 *)site{
//    if(site!=nil){
//        _site=site;
//    }
//}

- (NSMutableArray *)dataArr{
    if(_dataArr==nil){
        _dataArr=[NSMutableArray array];
    }
    return _dataArr;
}


- (TPKeyboardAvoidingTableView *)tableView{
    if(_tableView==nil){
        _tableView=[[TPKeyboardAvoidingTableView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT) style:UITableViewStyleGrouped];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.showsVerticalScrollIndicator=NO;
        [_tableView registerNib:[UINib nibWithNibName:@"QianDTableCell" bundle:nil] forCellReuseIdentifier:@"acell"];
        [_tableView registerNib:[UINib nibWithNibName:@"C_wladdCell_1" bundle:nil] forCellReuseIdentifier:@"bcell"];
        
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"旁站混凝土灌注桩-物料信息";
    [self.view addSubview:self.tableView];
    titleArr=@[@"钢筋混凝土灌注桩(非水下混凝土)",@"钢筋混凝土灌注桩(水下混凝土)",@"护坡桩",@"CFG桩",@"其他"];
    //添加右上方提交按钮
    if(self.isEdit){
        self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"wancheng"] style:UIBarButtonItemStyleDone target:self action:@selector(clickSave)];
    }

    NSLog(@"data:%@",self.dataArr);
    
}


//!!!!:保存视图
- (void)clickSave{
    //保存修改后数据 传值到上一界面
    self.dataBlock(self.dataArr);
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 3;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 46;
}

//头部视图
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    HeadView_1 *header=[[HeadView_1 alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, 46)];
    
    header.title.text=[NSString stringWithFormat:@"  %@",titleArr[section]];
    
    //改变颜色
    if(section%2==0){
        header.title.textColor=[UIColor colorWithRed:0.07 green:0.54 blue:0.49 alpha:1.00];
        header.backgroundColor=[UIColor colorWithRed:0.07 green:0.54 blue:0.49 alpha:1.00];
    }else{
        header.title.textColor=[UIColor colorWithRed:0.64 green:0.25 blue:0.11 alpha:1.00];
        header.backgroundColor=[UIColor colorWithRed:0.64 green:0.25 blue:0.11 alpha:1.00];
    }
    return header;
}

//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //根据组 获得数据
    NSMutableDictionary *dic=[self.dataArr objectAtIndex:indexPath.section];
    
    if(indexPath.row==0){
        C_wladdCell_1 *wlcell=[tableView dequeueReusableCellWithIdentifier:@"bcell" forIndexPath:indexPath];

        wlcell.text1Block=^(NSString *values){
            [dic setValue:values forKey:@"柱径"];
        };
        
        wlcell.text2Block=^(NSString *values){
            [dic setValue:values forKey:@"桩长"];
        };
        
        [wlcell configTitle:@"桩径:" Andtitle2:@"桩长:" AndText1:dic[@"柱径"] AndText2: dic[@"桩长"]];
        
        return wlcell;
        
    }else if (indexPath.row==1){
        C_wladdCell_1 *wlcell=[tableView dequeueReusableCellWithIdentifier:@"bcell" forIndexPath:indexPath];

        wlcell.text1Block=^(NSString *values){
            [dic setValue:values forKey:@"设计砼标号"];
        };
        
        wlcell.text2Block=^(NSString *values){
            [dic setValue:values forKey:@"单桩设计方量m3"];
        };
        
        [wlcell configTitle:@"设计砼标号:" Andtitle2:@"单桩设计方量m³:" AndText1:dic[@"设计砼标号"] AndText2:dic[@"单桩设计方量m3"]];
        
       return wlcell;
        
    }else{
        QianDTableCell *cell=[tableView dequeueReusableCellWithIdentifier:@"acell" forIndexPath:indexPath];
        
        cell.textValueChangedBlock=^(NSString *values){
            [dic setValue:values forKey:@"设计砼坍落度mm"];
        };
        
        [cell configWithPlaceholder:@"请输入" andValue:dic[@"设计砼坍落度mm"] andLabel:@"设计砼坍落度mm:" andKeyType: UIKeyboardTypeDefault];
        
         return cell;
    }
}

#pragma mark scrollview
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    if (scrollView == self.tableView) {
        [self.view endEditing:YES];
    }
}
@end
